

/*
if (0=='0') {
    console.log("ture");
} else {
    console.log("false");
}
if (0==='0') {
    console.log("ture");
} else {
    console.log("false");
}
if (Math.abs(1 / 3 - (1 - 2 / 3)) < 0.0000001) {
    console.log("ture");
} else {
    console.log("false");
}

var arr = [1, 2, 3.14, 'Hello', null, true];

arr[0]; // 返回索引为0的元素，即1
arr[5]; // 返回索引为5的元素，即true
arr[6]; // 索引超出了范围，返回undefined

var str1= '这是一个字符串'

var str2= "这是一个字符串，和一个单引号'"

var str3= '这是一个字符串，和一个双引号"'

var str4= '这是一个字符串，还包括了单引号\'，和双引号"'
var str5= '这是一个字符串，还包括了单引号\'，和双引号"，和一个反斜杠\\'
var str6= '这是一个字符串，还包括了单引号\'\t，和双引号"\n，和一个反斜杠\\'

console.log('我\n就是\n彭于晏\n本人')

console.log(`我
    就是
    彭于晏
本人
`);

var name = '卢本伟';
var age = 20;
var message = '你好, ' + name + ', 你今年' + age + '岁了!';
alert(message);

var name = '卢本伟';
var age = 20;
var message = `你好, ${name}, 你今年${age}岁了!`;
alert(message);

var s = 'Test';
s[0] = 'X';
alert(s); // s仍然为'Test'

var str =''

for (var i = 0; i < str.length;i++) {
    console.log(str[i])
}

console.log(str[100])

str[0]='10086';

var arr = [1, 2, 3];
arr.length; // 3
arr.length = 6;
arr; // arr变为[1, 2, 3, undefined, undefined, undefined]
arr.length = 2;
arr; // arr变为[1, 2]

var arr = ['A', 'B', 'C'];
arr[1] = 99;
arr; // arr现在变为['A', 99, 'C']

var arr = [[1, 2, 3], [400, 500, 600], '-']
var x = arr[1]
console.log(x[1]);

console.log('欢迎'+arr[0]+','+arr[1]+','+arr[2]+'和'+arr[3]+'同学');

var arr = [56454,87,87,944,99,4]

arr.soft1Sort = function (fn)
{
for(var j = 0; j< this.length; j++)
{
var item = this[j]
var idx = 0

for(var i = j+1; i < this.length;i++)
{
    if (fn(item,this[i])) {
        item = this[i]
        idx = i
    }
}
if (this[j] !== item) {
    var a = this[j]
    this[j] = this[idx]
    this[idx] = a
}
console.log(arr)
}
}
arr.soft1Sort(function (a,b) {
    return a > b
})

var arrrr=[45,545,777,11,2222,465456]

arrrr.sort2Sort = function (fn) {
    if (fn===underfined) {
        fn=(a,b)=>a>b
    }
    for(var i = 0; i<this.length;i++)
    {
       for(var j = 0;j<this.length;j++)
       {
           if (fn(this[i],this[j]<0)) {
               var a = this[j];
               this[j]=this[i];
               this[i]=a;
           } 

       }

    }
    console.log(arrrr);
}
arrrr.sort2Sort(function (a,b) {
    return a-b
});


var arr = [1,54,313,444,88,949,7]

function bubbleSort(arr) {
    var len = arr.length;
    for(var i = 0; i < len - 1; i++)
    {
        for(var j = 0; j < len - 1; j++)
        {
            if (arr[j] > arr[j+1]) {
                var temp = arr[j+1];
                arr[j+1] = arr[j];
                arr[j] = temp;
            }
        }
        
    } 
    return arr;

}
console.log(bubbleSort(arr));

function selectionSort(arr) {
    var len = arr.length;
    var minIndex,temp;
    for(var i = 0; i < len-1; i++)
    {
        minIndex = i;
        for(var j =i + 1;j < len - 1;j++){
            if (arr[j]<arr[minIndex]) {
                minIndex = j;
            }
        }
        temp = arr[i];
        arr[i] = arr[minIndex];
        arr[minIndex] = temp;
    }
    return arr;
}
console.log(selectionSort(arr));

function insertionSort(arr) {
    var len = arr.length;
    var preIndex,current;
    for(var i =1;i < len;i++)
    {
        preIndex = i-1;
        current = arr[i];
        while (preIndex >= 0 && arr[preIndex] > current) {
            arr[preIndex + 1] =arr[preIndex];
            preIndex--;

        }
        arr[preIndex + 1] = current;

    }
    return arr;
}
console.log(selectionSort(arr));

 var strs = ['fuck','fish','faker']

function ASS(strs) {
    var len = strs.length;
    if (len === 0) {
        return ""
    }
    var xqc = strs[0];
    for(var i = 1; i < len;i++)
    {
        var j = 0;
        for(j < xqc.length() ; j < strs[i].length(); j++ )
        {
            if (xqc.charAt(j) != strs[i].charAt(j)) {
                break;
            }
        }
        xqc = xqc.substring(0,j);
        if (xqc.equals("")) {
            return xqc;
        }
    }
    return xqc;

}
console.log(ASS(xqc));

var arr=["ddsfsf","ddsgeg","ddseterht"]

for(i=1;i<arr.length;i++)
{
    var temp="";
    for(j=1;j<arr[0].length;j++)
    {
        if (arr[0][j]==arr[i][j]) {
            temp=temp+arr[0][j]
        }

    }
    arr[0]=temp;
}
console.log();

console.log('window inner size: ' + window.innerWidth + ' x ' + window.innerHeight);



var nums = [1,5,4,6,4,5,4,1,3,8]

var findLHS = function(nums) {
    nums.sort((a, b) => a - b);
    let begin = 0;
    let res = 0;
    for (let end = 0; end < nums.length; end++) {
        while (nums[end] - nums[begin] > 1) {
            begin++;
        }
        if (nums[end] - nums[begin] === 1) {
            res = Math.max(res, end - begin + 1);
        }
    }
    return res;
};

var finder = function(nums) {
    nums.sort();
    let zero = 0;
    let result =0;
    for (let end = 0; end < nums.length; end++) {
        while (nums[end] - nums[zero] > 1) {
            zero++;
        }
        if (nums[end] - nums[zero] === 1) {
            result = Math.max(result,end - zero + 1);
        }
        
    }
    return result;

}
console.log(finder(nums));
console.log(findLHS(nums));

var ass = function(nums){
    const cat = new Map();
    let result = 0;
    for (const num of nums){
        cat.set(num, (cat.get(num) || 0) + 1)

    }
    for(const key of cat.keys()){
        if (cat.has(key + 1)) {
            result = Math.max(result,cat.get(key) + cat.get(key +1));
        }

    }
    return result;
};


console.log(ass(nums));



//浮点数的相等比较：
//Math.abs()
if ( Math.abs(1 / 3 - (1 - 2 / 3)) < 0.0000000001) {
    console.log("real");
} else {
    console.log("F");
}

//多行字符串：
console.log(`我
就是
彭于晏`);

//横板字符串
var name = 'dd';
var age = 12;
var message = 'ss'+ name + '' + age + '';
var message = `ss, ${name}, ${age} `

//操作字符串
 var s = 'dd';
 s[0] = 's';

 alert (s);

 var str = ';'

 for (let index = 0; index < array.length; index++) {
    console.log(str[i]);
 }

console.log(str[100]);
str[0] = "21465456";


var nums = [2,5,6,4,8,9,1,5,4]
var finder = function (nums) {
    nums.sort((a,b) => a-b);
    var begin = 0;
    var rel = 0;//1
    for (let end = 0; end < nums.length; end++) {
        while (nums[end] - nums[begin] > 1) {
            begin++;
        }
        if (nums[end] - nums[begin] === 1) {
            rel = Math.max(rel,end - begin + 1)//1//
        }
        
    }
    return rel;
}
console.log(finder(nums));
console.log(nums);

var strs = ['fuck','fish','faker']

function ASS(strs) {
    var len = strs.length;
    if (len === 0) {
        return ""
    }
    var xqc = strs[0];
    for(var i = 1; i < len;i++)
    {
        var j = 0;
        for(j < xqc.length() ; j < strs[i].length(); j++ )
        {
            if (xqc.charAt(j) != strs[i].charAt(j)) {
                break;
            }
        }
        xqc = xqc.substring(0,j);
        if (xqc.equals("")) {
            return xqc;
        }
    }
    return xqc;

}
console.log(ASS.xqc);

    


var str = "asssdfewwwdagfasdg"
var ass = function (str) {
    var len = str;
    var a = 0;
    for (let i = 0; i < str.length; i++) {
        for (let j = 1; j < str.length-1; j++) {
           if ( str[i] === len[j]) {
               
           }
            
        }
        
    }
}

console.log(len[0]);
 
var lengthOfLongestSubstring = function (s) {
    const set = new Set(); //判断滑动窗口内是否有重复元素
    let i = 0,//滑动窗口右边界
        j = 0,//滑动窗口左边界
        maxLength = 0;
    if (s.length === 0) {//极端情况
        return 0;
    }
    for (i; i < s.length; i++) {
        if (!set.has(s[i])) {//当前元素不在set中 就加入set 然后更新最大长度，i++继续下一轮循环
            set.add(s[i]);
            maxLength = Math.max(maxLength, set.size);
        } else {
            //set中有重复元素不断让j++ 并删除窗口之外的元素 直到滑动窗口内没有重复的元素
            while (set.has(s[i])) {
                set.delete(s[j]);
                j++;
            }
            set.add(s[i]);//放心将s[i]加入set中
        }
    }
    return maxLength;
};


window.jQuery;
window.$;
typeof($);
console.log(window.jQuery);
console.log(window.$);
console.log(typeof($));

//+ 仅选择JavaScript
var dsfs = $('#ppp'); 
var id = document.getElementById('para-1');
 var js = document.getElementsByClassName("color-red");
 console.log(dsfs);
console.log($('p') )
//+ 仅选择Erlang
console.log(js);
console.log(id);
//+ 选择JavaScript和Erlang

//+ 选择所有编程语言

//+ 选择名字input

//+ 选择邮件和名字input

// 选择<p>JavaScript</p>:
var js = document.getElementById('test-p');

// 选择<p>Python</p>,<p>Ruby</p>,<p>Swift</p>:
var arr = document.getElementsByClassName("c-red");

// 选择<p>Haskell</p>:
var haskell = document.getElementsByTagName('p');

console.log(js);
console.log(arr);
console.log(haskell);

var selected = null;
// 分别选择所有语言，所有动态语言，所有静态语言，JavaScript，Lua，C等:

var selected = $('ul.lang li.lang-javascript');
console.log(selected);


var q = 'asda';
console.log(q.toUpperCase());
console.log('aas'.toUpperCase());
console.log('AWEF'.toLowerCase());
console.log(q.indexOf('d'));
console.log(q.indexOf('b'));
console.log(q.substring(0,3));
console.log(q.substring(1));
var number = [12,342,1,223,44,12];
console.log(number.indexOf(12));
console.log(number.indexOf(44));
console.log(number.indexOf(223));
console.log(number.slice(2));
console.log(number.slice(0,3));
console.log(number.pop());
console.log(number.push(2,31,2,1));
console.log(number.unshift('a','asd','cas'));
console.log(number.shift());
console.log(number.sort());
console.log(number.splice(0,3,'sdaf'));
var sad = number.concat('asda','asdaw');
console.log(sad);
console.log(number.join('b'));
console.log(number.join('.'));

var num = $('p');
console.log(num);
*/
var s = new Set([1,1,1,1,1,1,1]);
console.log(s);
var a = [1, 2, 3];
for (var x of a) {
}
console.log('你的浏览器支持for ... of');
var number = ['dfgsdfg','sdgre','2324ssf',23,323,44]
for (var x of number) {
    console.log(x);
}
for (var x of number) { // 遍历Map
    console.log(x[0] + '=' + x[1]);
}
number.name = 'Hello';
for (var key in number) {
                console.log(number[key]);                                                                                             
}
number.forEach(function (element,index) {
    console.log(element + ', index = ' + index);
}); 
var a = ['A', 'B', 'C'];
a.forEach(function (element) {
    console.log(element);
});
function foo(x) {
    console.log('x = ' + x); // 10
    for (var i=0; i<arguments.length; i++) {
        console.log('arg ' + i + ' = ' + arguments[i]); // 10, 20, 30
    }
}
foo(10, 20, 30);
fo(7,5,6,5);

function fo(a,b) {
    var i,rest = [];
    if (arguments.length > 2) {
        for (let i = 2; i < arguments.length; i++) {
           rest.push(arguments[i]);
            
        }
    }
    console.log(a);
    console.log(b);
    console.log(rest);
}



 function area_of_circle(r,pi) {
   // return r * r * (pi || 3.14);
   if(arguments.length>=2)
{
return pi*r*r;
}
else if(arguments.length==1)
{
return 3.14*r*r;
}
else return false;
}

if (area_of_circle(2) === 12.56 && area_of_circle(2, 3.1416) === 12.5664) {
    console.log('测试通过');
} else {
    console.log('测试失败');
}
function max(a, b) {
    if ( a > b) {
        return a;
                
    } else {
        return b;
                
    }

}
console.log(max(15, 20));
function pow(x){
    return x * x;
}
var arr = [1,2,3,4,5,6,7,8,9];
var rel = arr.map(pow);
console.log(rel);

var arr = [1, 3, 5, 7, 9];
function name(arr) {
    
}
arr.reduce(function (x, y) {
    return x + y;
});


function product(arr) {
    arr.reduce(function (x,y) {
        return x * y;
    })

}
if (product([1, 2, 3, 4]) === 24 && product([0, 1, 2]) === 0 && product([99, 88, 77, 66]) === 44274384) {
    console.log('测试通过!');
}
else {
    console.log('测试失败!');
}